package com.linkcard.list.manager;

import java.util.ArrayList;
import java.util.List;

import com.linkcard.list.model.Category;
import com.linkcard.list.persistence.CategoryDao;

public class CategoryManagerImpl implements CategoryManager {

	private CategoryDao categoryDao=null;
	//添加类别
	public boolean addCategory(Category category) {
		return categoryDao.addCategory(category);
	}
	public CategoryDao getCategoryDao() {
		return categoryDao;
	}
	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}
	//获得类别列表
	public List categoryList(Integer columnId,int pid) {
		return this.categoryDao.categoryList(columnId,pid);
	}
	//修改类别
	public boolean modifyCategory(Category category) {
		// TODO Auto-generated method stub
		return this.categoryDao.modifyCategory(category);
	}
	//删除类别
	public boolean deleteCategory(Category category) {
		return this.categoryDao.deleteCategory(category);
	}
	//查找类别
	public Category findCategory(Integer categoryId) {
		return this.categoryDao.findCategory(categoryId);
	}
	//按条件分类
	public List categoryListBySelect(int columnId,int pid) {
		List list=new ArrayList();
		List categoryList=this.categoryDao.categoryList(columnId,-1);
		for(int i=0;i<categoryList.size();i++)
		{
			Category category=(Category)categoryList.get(i);
			List temp=new ArrayList();
			temp.add(category);
			if(pid!=-1)
			{
			List subList=this.categoryDao.categoryList(columnId,category.getId());
			temp.add(subList);
			}
			list.add(temp);
		}
		return list;
	}

}
